package com.qc.Thrift;

import org.apache.thrift.TProcessor;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.protocol.TProtocolFactory;
import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TThreadPoolServer;
import org.apache.thrift.transport.TServerSocket;
import org.apache.thrift.transport.TServerTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;

import static java.lang.Thread.sleep;

/**
 * Hello world!
 *
 */
public class App {
//    public static void main( String[] args )
//    {
//        System.out.println( "Hello World!" );
//    }

    public static void main(String[] args) throws Exception {
        // 设置传输通道 - 普通IO流通道
//        TTransport transport = new TSocket("localhost", 7911);
        TTransport transport = new TSocket("47.100.197.222", 7911);
        transport.open();

        //使用高密度二进制协议
        TProtocol protocol = new TCompactProtocol(transport);

        //创建Client
        Hello.Client client = new Hello.Client(protocol);

        long start = System.currentTimeMillis();
        for(int i=0; i<30; i++){
            System.out.println("helloBoolean：" +  client.helloBoolean(false));
            System.out.println("helloInt：" + client.helloInt(i));
            System.out.println("helloNull：" + client.helloNull());
            System.out.println("helloString：" + client.helloString("dongjian"));
            client.helloVoid();
            sleep(100);
        }
        System.out.println("耗时：" + (System.currentTimeMillis() - start));

        //关闭资源
        transport.close();
    }
}
